import 'dart:async';

import 'package:flutter/material.dart';
import '../../base/MyScaffold.dart';
import '../../utils/Tool/MyTools.dart';
import '../../widgets/MyLocalImage.dart';
import '../../widgets/TextView.dart';
import 'package:get/get.dart';

import '../../api/ApiUtils.dart';
import '../../api/request/UserInfoRequest.dart';
import '../../res.dart';
import '../../utils/color/ColorUtils.dart';
import '../../widgets/MyLocalImage.dart';
import '../../widgets/UpLoadPicsWidget.dart';

class MyFeedback extends StatefulWidget {
  const MyFeedback({Key? key}) : super(key: key);

  @override
  State<MyFeedback> createState() => _FeedbackState();
}

class _FeedbackState extends State<MyFeedback> {
  late List<String> imgPathList;
  String content = "";
  bool can = false;

  @override
  void initState() {
    // TODO: implement initState
    imgPathList = [];
    super.initState();
  }

  alertAddProduct() {
    Get.defaultDialog(
      radius: 10,
      contentPadding: const EdgeInsets.only(top: 12, bottom: 12),
      titlePadding: const EdgeInsets.only(top: 20),
      content: Container(
        width: MediaQuery.of(context).size.width,
        child: Column(
          children: [
            const MyLocalImage(
              Res.tips_icon_success2,
              width: 56,
              height: 56,
            ),
            TextView(
              "thanks".tr,
              margin: const EdgeInsets.only(top: 20),
              style: TextStyle(
                  color: ColorUtils.text,
                  fontSize: 18,
                  fontWeight: FontWeight.bold),
            ),
            TextView(
              "experience".tr,
              margin: const EdgeInsets.only(top: 12),
              maxLines: 2,
              textAlign: TextAlign.center,
              padding: const EdgeInsets.symmetric(horizontal: 32),
              style: TextStyle(color: ColorUtils.text_),
            ),
            TextView(
              "ok".tr,
              alignment: Alignment.center,
              height: 44,
              backcolor: rgba(255, 78, 77, 1),
              margin: const EdgeInsets.only(top: 32, left: 32, right: 32),
              radius: BorderRadius.circular(6),
              textAlign: TextAlign.center,
              padding: const EdgeInsets.symmetric(horizontal: 32),
              style: const TextStyle(
                  color: Colors.white,
                  fontSize: 16,
                  fontWeight: FontWeight.bold),
              onclick: () {
                Get.back();
                Timer(const Duration(milliseconds: 500), () {
                  Get.back();
                });
              },
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MyScaffold(
      resizeToAvoidBottomInset: false,
      body: Container(
        child: Column(
          children: [
            Expanded(
                child: Column(
              children: [
                const MyLocalImage(
                  Res.faq_img_problem,
                  width: 100,
                  height: 100,
                ),
                TextView(
                  "encountered".tr,
                  margin: const EdgeInsets.only(top: 10, bottom: 24),
                  style: TextStyle(color: ColorUtils.text, fontSize: 18),
                  onclick: () {
                    alertAddProduct();
                  },
                ),
                Expanded(
                    child: Container(
                  margin:
                      const EdgeInsets.only(left: 16, right: 16, bottom: 20),
                  padding:
                      const EdgeInsets.symmetric(vertical: 16, horizontal: 20),
                  decoration: BoxDecoration(
                      color: rgba(247, 247, 247, 1),
                      borderRadius: BorderRadius.circular(8)),
                  child: TextField(
                    maxLines: 999,
                    onChanged: (v) {
                      content = v;
                      if (!MyTools.stringIsEmpty(content) &&
                          content.length > 6) {
                        can = true;
                      } else {
                        can = false;
                      }
                      setState(() {});
                    },
                    decoration: InputDecoration(
                        border: InputBorder.none,
                        hintStyle: const TextStyle(color: Colors.black26),
                        hintText: "problem_tips".tr),
                  ),
                )),
                Container(
                  height: 86,
                  alignment: Alignment.centerLeft,
                  margin:
                      const EdgeInsets.symmetric(vertical: 16, horizontal: 16),
                  // child: GridView.builder(
                  //   gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  //       childAspectRatio: 1.0,
                  //       crossAxisSpacing: 6,
                  //       crossAxisCount: 4),
                  //   itemBuilder: (c, index) {
                  //     return Container(
                  //       child: const MyLocalImage(
                  //         Res.fqa_icon_add,
                  //         width: 76,
                  //         height: 76,
                  //       ),
                  //     );
                  //   },
                  //   itemCount: 4,
                  // ),
                  child: UpLoadPicsWidget(
                    itemWidth: 80,
                    itemHeight: 80,
                    spacing: 10,
                    radius: 6,
                    rebackResultFunc: (imgPathList) async {
                      this.imgPathList = imgPathList;
                    },
                  ),
                ),
              ],
            )),
            const Divider(
              height: 1,
            ),
            // Container(
            //   margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
            //   alignment: Alignment.center,
            //   child: MaterialButton(
            //     onPressed: () {
            //       if (MyTools.stringIsEmpty(content)) {
            //         MyToast().show("empty".tr, icon_tips: false);
            //         return;
            //       }
            //       apiShow(
            //           api: api_userInfo_feedback(
            //               content: content, images: imgPathList),
            //           success: (value) {
            //             alertAddProduct();
            //           },
            //           failure: (value) {
            //             Get.back();
            //           });
            //     },
            //     minWidth: double.infinity,
            //     color: rgba(255, 78, 77, 1),
            //     height: 48,
            //     shape: RoundedRectangleBorder(
            //       borderRadius: BorderRadius.circular(6),
            //     ),
            //     child: TextView(
            //       "submit".tr,
            //       style: const TextStyle(color: Colors.white),
            //     ),
            //   ),
            // ),
            Container(
              margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
              alignment: Alignment.center,
              height: 48,
              decoration: BoxDecoration(
                  color: rgba(255, 78, 77, can ? 1 : 0.3),
                  borderRadius: BorderRadius.circular(6)),
              child: TextView(
                "submit".tr,
                alignment: Alignment.center,
                style: const TextStyle(color: Colors.white),
                onclick: () {
                  if (can) {
                    apiShow(
                        api: api_userInfo_feedback(
                            content: content, images: imgPathList),
                        success: (value) {
                          alertAddProduct();
                        },
                        failure: (value) {
                          Get.back();
                        });
                  }
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
